﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" ValidateRequest="false" Inherits="System.Web.Mvc.ViewPage<Hotnet.Entity.News>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
<%
	NewsCategory category = ViewData["Category"] as NewsCategory; 
%>
<%=string.Format("新增新闻 - <{0}> - 新闻管理 - Hotent后台管理", category.Name) %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
	NewsCategory category = ViewData["Category"] as NewsCategory;
%>
	<h2><%=Model==null?"新增新闻":"修改新闻" %></h2>

	<div class="m5">
		<%=Html.ActionLink("返回" + category.Name, "Index", "AdminNewsCategory", new { id = category.CategoryID }, null)%>
	</div>
	<div id="hitDom" class="dn tac">
		<div style="color:white;font-weight:bold;background-color:#B93D00;padding:5px;width:120px;margin-left:auto;margin-right:auto;">保存成功!</div>
	</div>
	<% using (Html.BeginForm("Create", "AdminNews", FormMethod.Post, new { enctype = "multipart/form-data",id="formCreateOrUpdate"}))
	{%>
		<input type="hidden" name="CategoryID" value="<%=category.CategoryID %>" />
		<input type="hidden" name="OrderNo" value="<%=ViewData["OrderNo"]%>" />
		<table width="100%" class="list ma">
			<tr>
				<td align="right" style="width:20%">新闻标题:</td>
				<td><%= Html.TextBox("Title")%></td>
			</tr>
			<tr>
				<td align="right">新闻Tag:</td>
				<td><%= Html.TextBox("Tags")%></td>
			</tr>
			<tr>
				<td align="right">新闻来源:</td>
				<td><%=Html.DropDownList("sourceFromID", ViewData["SourceFromList"] as IEnumerable<SelectListItem>, "==请选择==", new { style = "width:170px;" })%></td>
			</tr>
			<tr>
				<td align="right">新闻日期:</td>
				<td><%= Html.TextBox("NewsTime")%></td>
			</tr>
			<%--<tr>
				<td align="right">所属列表:</td>
				<td><%=Html.DropDownList("DefineType", ConvertEnumToSelectList.ComposeSelectListFromEnum<EnumDefineType>().Reverse())%></td>
			</tr>--%>
			<tr>
				<td align="right">图片</td>
				<td>
					<input type="file" name="newsImage" id="newsImage" />
				</td>
			</tr>
			<tr>
				<td align="right">图片预览</td>
				<td>
					<img src='<%=Model==null?"":Model.ImagePath %>' style="width:100px; height:70px;" alt="图片" />
				</td>
			</tr>
			<tr>
				<td align="right">
					新闻页
				</td>
				<td>
				<%if (Model != null)
					{ 
					%>
						<%for (int i = 0; i < Model.NewsContent.Count; i++)
					{%>
							<a href="/AdminNews/Edit/<%=Model.NewsID %>?categoryId=<%=category.CategoryID%>&orderNo=<%=Model.NewsContent[i].OrderNo%>">
								<span style="color:<%=Model.NewsContent[i].OrderNo==int.Parse(ViewData["OrderNo"].ToString())?"red;font-weight:bolder;":""%>">
								<%=Model.NewsContent[i].OrderNo==int.Parse(ViewData["OrderNo"].ToString())?string.Format("[{0}]",Convert.ToString((i+1))):Convert.ToString((i+1))%>
								</span>
							</a>
							
						<%} %>
						<a href="/AdminNews/Edit/<%=Model.NewsID %>?categoryId=<%=category.CategoryID%>&orderNo=<%=Model.NewsContent.Max(x=>x.OrderNo)+1%>">
								<%=(Model.NewsContent.Max(x => x.OrderNo) + 1) == int.Parse(ViewData["OrderNo"].ToString()) ? string.Format("[{0}]", "<span style='color:red;font-weight:bolder;'>创建新页</span>") :"创建新页"%>
						</a>
						<%if ((Model.NewsContent.Max(x => x.OrderNo) + 1) != int.Parse(ViewData["OrderNo"].ToString())&&Model.NewsContent.Count>1)
					{ %>
							<a href="javascript:deleteNewsPage(<%=Model.NewsID %>,<%=ViewData["OrderNo"] %>)">删除此页</a>
						<%} %>
						
				<%} %>
				</td>
			</tr>
			<tr>
				<td align="right">新闻内容:</td>
				<td>
					<%= Html.TextArea("Content")%>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="保存" />
				</td>
			</tr>
		</table>
	
	<% } %>

	<div class="m5">
		<%=Html.ActionLink("返回" + category.Name, "Index", "AdminNewsCategory", new { id = category.CategoryID }, null)%>
	</div>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
<script type="text/javascript">
	var newsId = '<%=Model==null?0:Model.NewsID %>';
	$(document).ready(function(){
		$(function() {
		
		if (newsId != 0) {
					$("#formCreateOrUpdate").attr("action", "/AdminNews/Edit/" + newsId);
				}
		<%if(ViewData["Successed"] != null){ %>
		$("#hitDom").fadeIn(3000, function(){
			setTimeout(function(){$("#hitDom").fadeOut(3000);}, 3000);
		});
		<%} %>
		var oFCKeditor = new FCKeditor('Content', "100%", "450");
		oFCKeditor.ReplaceTextarea();
	});
		
	});
	
	function deleteNewsPage(newsID,orderNo){
		if (!confirm("确定删除?"))
				return ;
			$.ajax({
				type: "POST",
				url: "/AdminNews/DeleteNewsPage",
				data: ({ newsId: newsID, orderNo: orderNo }),
				success: function(msg) {
					alert(msg);
					window.location="/AdminNews/Edit/"+newsID;
				}
			});
	}
	
</script>
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="StyleContent" runat="server">
</asp:Content>

